from django import forms
from rest_framework import serializers
from .models import Course
from django.contrib.auth.models import User

# class CourseForm(forms.ModelForm):
#     class Meta:
#         model=Course
#         fields=('name','introduction','teacher','price')

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'

class CourseSerializer(serializers.ModelSerializer):
    # teacher是外键字段，设置只读
    teacher = serializers.ReadOnlyField(source='teacher.username')
    class Meta:
        model=Course
        fields='__all__'
        depth=2


# class CourseSerializer(serializers.HyperlinkedModelSerializer):
#     # teacher是外键字段，设置只读
#     teacher = serializers.ReadOnlyField(source='teacher.username')
#     class Meta:
#         model=Course
#
#         fields=('id','url','name','introduction','teacher','price','create_at','update_at')